export class Storage {
  storage: globalThis.Storage = localStorage;

  setItem(key: string, value: any) {
    if (typeof value === "undefined") return;
    if (typeof value === "string") {
      this.storage.setItem(key, value);
      return;
    }
    this.storage.setItem(key, JSON.stringify(value));
  }

  getItem(key: string) {
    try {
      return JSON.parse(localStorage.getItem(key) || "");
    } catch {
      return localStorage.getItem(key);
    }
  }

  removeItem() {}

  clear() {}
}

const l = new Storage();

l.setItem("list", ["a", "b", "c", "d"]);
l.setItem("str", "1,2,3,34,5");
l.setItem("arr", [{ name: "张三", like: [{ age: 18 }] }]);

console.log(l.getItem("list"));
console.log(l.getItem("str"));
console.log(l.getItem("arr"));
